package com.yunding.house.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunding.house.mapper.AgentMapper;
import com.yunding.house.pojo.Agent;
import com.yunding.house.service.AgentService;
import com.yunding.house.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.management.resources.agent;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author linyang
 * @since 2019-08-15
 */
@Service
public class AgentServiceImpl implements AgentService {

    @Autowired
    private AgentMapper agentMapper;

    @Override
    public void save(Agent agent) {
        agentMapper.insert(agent);
    }

    @Override
    public void del(long id) {
        agentMapper.deleteById(id);
    }

    @Override
    public void update(Agent agent) {
        agentMapper.updateById(agent);
    }

    @Override
    public List<Agent> findAll() {
        return agentMapper.selectList(null);
    }

    @Override
    public Agent selectone(long id) {
        return agentMapper.selectById(id);
    }

    @Override
    public PageResult search(int page, int size, Agent agent) {
        Page<Agent> agentPage = new Page<>(page, size);
        //条件对象
        QueryWrapper queryWrapper = new QueryWrapper(new Agent());
        //模糊查询name
        queryWrapper.like("agent_Companyname", agent.getAgentCompanyname());
        IPage iPage = agentMapper.selectPage(agentPage, queryWrapper);
        return new PageResult(iPage.getTotal(), iPage.getRecords());
    }

    @Override
    public List<Agent> like(String agentname) {
        QueryWrapper queryWrapper = new QueryWrapper(agentname);
        queryWrapper.like("agent_Companyname", agentname);
        return agentMapper.selectList(queryWrapper);
    }


}
